import glob,os,stat,time,sys
#import thread
# -*- coding: utf-8 -*-
import ConfigParser
config = ConfigParser.ConfigParser()
config.readfp(open('config.ini'))
myport = config.get("config","PORT")
mycmd = "netstat -an |grep 0.0.0.0:"+myport+" |wc -l"
def main():
    while True:
        retcs = int(os.popen(mycmd).read())
        log('The System runing..%d.' % retcs)
        if retcs <1:
           os.system("./chat")
           #thread.start_new_thread(self.monitor)
           log('reboot...'+mycmd)
           f = file('LOG/CS_LOG.txt','a')
           fs_log = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"\n"
           f.write(fs_log)
           f.close()
        time.sleep(7)      
    return
def log(str):
        print >>sys.stderr, str
if __name__ == "__main__":
    main()
